//
//  WXPLivenessFailView.m
//  MexicoLoan
//
//  Created by wxp on 2025/4/13.
//
//

#import "WXPLivenessFailView.h"

@interface WXPLivenessFailView ()

@end

@implementation WXPLivenessFailView

#pragma mark - lazy
- (UIView *)viewBack
{
    if (_viewBack == nil) {
        _viewBack = [UIView  new];
        _viewBack.userInteractionEnabled = true;
        _viewBack.backgroundColor = COLOR_WHITE;
        [GlobalMethod setRoundView:_viewBack color:COLOR_WHITE numRound:16 width:0];
        _viewBack.width = SCREEN_WIDTH-2*LEFT_MARDIN;
    }
    return  _viewBack;
}
- (UIButton *)btnClose{
    if (_btnClose == nil) {
        _btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnClose.tag = 1;
        [_btnClose addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_btnClose setImage:[UIImage imageNamed:@"icon-login-close"] forState:UIControlStateNormal];
        _btnClose.widthHeight = XY(24+2*LEFT_MARDIN, 24+2*LEFT_MARDIN);
    }
    return _btnClose;
}
- (UIImageView *)imageLogo
{
    if (_imageLogo == nil) {
        _imageLogo = [UIImageView  new];
        _imageLogo.widthHeight = XY(30, 30);
        _imageLogo.image = [UIImage imageNamed:@"icon-error-red"];
    }
    return  _imageLogo;
}
- (UILabel *)labelTitle
{
    if (_labelTitle == nil) {
        _labelTitle = [UILabel  new];
        _labelTitle.textColor = COLOR_RED;
        _labelTitle.fontNum = 18;
    }
    return  _labelTitle;
}
- (UILabel *)labelContent
{
    if (_labelContent == nil) {
        _labelContent = [UILabel  new];
        _labelContent.textColor = COLOR_CONTENT;
        _labelContent.fontNum = 12;
        _labelContent.numberOfLines = 0;
        _labelContent.lineSpace = 3;
    }
    return  _labelContent;
}
- (UILabel *)labelSubTitle
{
    if (_labelSubTitle == nil) {
        _labelSubTitle = [UILabel  new];
        _labelSubTitle.textColor = COLOR_BLACK;
        _labelSubTitle.font = [UIFont boldSystemFontOfSize:12];
    }
    return  _labelSubTitle;
}
- (UILabel *)labelDesc
{
    if (_labelDesc == nil) {
        _labelDesc = [UILabel  new];
        _labelDesc.textColor = COLOR_LIGHT_GRAY;
        _labelDesc.fontNum = 12;
        _labelDesc.numberOfLines = 0;
        _labelDesc.lineSpace = 3;
    }
    return  _labelDesc;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, SCREEN_HEIGHT);
        self.leftTop = XY(0, 0);
        self.backgroundColor = [UIColor colorWithHexString:@"000000" alpha:0.4];
        [self addSubView];
        self.userInteractionEnabled = YES;
    }
    return self;
}

//添加subview
- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.btnClose];
    [self.viewBack addSubview:self.imageLogo];
    [self.viewBack addSubview:self.labelTitle];
    [self.viewBack addSubview:self.labelContent];
    [self.viewBack addSubview:self.labelSubTitle];
    [self.viewBack addSubview:self.labelDesc];
    //初始化页面
    [self resetViewWithModel:nil];
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    [NSObject clickFeedback];
    [sender addClickAnimate];
    switch (sender.tag) {
        case 1:
        {
            [self removeFromSuperview];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 刷新view
- (void)resetViewWithModel:(id)model{
    self.btnClose.rightTop = XY(self.viewBack.width, 0);
    
    self.imageLogo.centerXTop = XY(self.viewBack.width/2, 56);
    [self.labelTitle fitTitle:@"Reconocimiento facial fallado" variable:0];
    self.labelTitle.centerXTop = XY(self.imageLogo.centerX, self.imageLogo.bottom+13);
    
    [self.labelContent fitTitle:@"Verifica tu conexión a Internet. Toma una nueva foto que cumpla con los siguientes requisitos" variable:self.viewBack.width-30-30];
    self.labelContent.leftTop = XY(30, self.labelTitle.bottom+30);
    
    [self.labelSubTitle fitTitle:@"Consejos" variable:0];
    self.labelSubTitle.leftTop = XY(self.labelContent.left, self.labelContent.bottom+25);
    
    [self.labelDesc fitTitle:@"1. Fotografía desde el frente.\n2. Hazlo en un lugar sin distracciones.\n3. No ocultes tu cara.\n4. Sujeta el teléfono de manera vertical y con firmeza" variable:0];
    self.labelDesc.leftTop = XY(self.labelSubTitle.left, self.labelSubTitle.bottom+10);
    
    self.viewBack.height = self.labelDesc.bottom+40;
    self.viewBack.centerXCenterY = XY(self.width/2, self.height/2-20);
}





@end
